package com.angus.modules.content.service.impl;

import com.angus.common.core.utils.StringUtils;
import com.angus.modules.content.domain.*;
import com.angus.modules.content.dto.MyFeedBackDto;
import com.angus.modules.content.repository.*;
import com.angus.modules.content.service.IMyFeedBackService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * @author lineCode
 */
@Service
public class MyFeedBackServiceImpl implements IMyFeedBackService {
    @Resource
    private MyFeedBackRepository myFeedBackRepository;

    @Override
    public Boolean add(MyFeedBackDto dto, Long userId) {
        MyFeedBack in = new MyFeedBack();
        in.setUserId(userId);
        in.setFeedType(dto.getFeedType());
        in.setImages(dto.getImages());
        in.setTitle(dto.getTitle());
        in.setRemark(dto.getRemark());
        in.setCreateBy(String.valueOf(userId));
        in.setUpdateBy(String.valueOf(userId));
        in.setStatus(1);
        return myFeedBackRepository.save(in);
    }
    @Override
    public List<MyFeedBack> query(MyFeedBackDto dto, Long userId){
        LambdaQueryWrapper<MyFeedBack> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MyFeedBack::getUserId, userId);
        queryWrapper.eq(MyFeedBack::getDelFlag, 0);
        // 反馈类型
        if (StringUtils.isNotEmpty(dto.getFeedType())) {
            queryWrapper.eq(MyFeedBack::getFeedType, dto.getFeedType());
        }
        // 反馈状态查询
        if (dto.getStatus() != null && dto.getStatus() != 0) {
            queryWrapper.eq(MyFeedBack::getStatus, dto.getStatus());
        }
        queryWrapper.orderByDesc(MyFeedBack::getUpdateTime);
        List<MyFeedBack> list = myFeedBackRepository.getBaseMapper().selectList(queryWrapper);
        return list != null ? list : Collections.emptyList();
    }

    @Override
    public MyFeedBack getById(Long id){
        return myFeedBackRepository.getBaseMapper().selectById(id);
    }
}
